package org.dicr.util.jds.gui;

import java.awt.*;

import org.dicr.event.*;

import com.borland.dbswing.*;
import com.borland.dx.dataset.*;

/***********************************************************************************************************************
 * @author Igor A Tarasov me@dicr.dn.ua
 * @version 021025
 **********************************************************************************************************************/
public class DataBrowserTablePanel extends DataDetailPanel {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	protected JdbTable dataTable = new JdbTable();

	/*******************************************************************************************************************
	 * Конструктор
	 ******************************************************************************************************************/
	public DataBrowserTablePanel() {
		try {
			jbInit();
		} catch (Exception ex) {
			DicrExceptionHandler.handleException(ex, this);
		}
	}

	/*******************************************************************************************************************
	 * Инициализация
	 ******************************************************************************************************************/
	private void jbInit() {
		this.add(this.scrollPane, BorderLayout.CENTER);
		this.scrollPane.setViewportView(this.dataTable);
		this.controlPanel.setControlButtonsMask(DataControlPanel.BUTTON_ADD | DataControlPanel.BUTTON_CANSEL
		        | DataControlPanel.BUTTON_DEL | DataControlPanel.BUTTON_FIRST | DataControlPanel.BUTTON_LAST
		        | DataControlPanel.BUTTON_NEXT | DataControlPanel.BUTTON_POST | DataControlPanel.BUTTON_PREV
		        | DataControlPanel.BUTTON_REFRESH | DataControlPanel.BUTTON_SAVE);
		this.dataTable.setAutoscrolls(true);
	}

	/*******************************************************************************************************************
	 * Установка свойства редактируемости
	 ******************************************************************************************************************/
	@Override
	public void setEditable(boolean theEditable) {
		if (this.editable != theEditable) {
			super.setEditable(theEditable);
			this.dataTable.setEditable(theEditable);
		}
	}

	/*******************************************************************************************************************
	 * Установка источника данных
	 ******************************************************************************************************************/
	@Override
	public void setDataSet(DataSet theDataset) {
		if (this.dataset != theDataset) {
			super.setDataSet(theDataset);
			this.dataTable.setDataSet(theDataset);
		}
	}
}
